/**
 * Created by chocolate on 16/4/28.
 */
'use strict'

import React, {
	Component,
	View,
	Text,
	StyleSheet,
}from 'react-native';

var loginCheckQuery = require('./Query').query;
var UsrLogin = require('./Login');
// var PushNotification = require('./PushNotification');
var thiz = null;
class HomePage extends Component{

	constructor(props){
		super(props);
		this.state = {
			// account:'',
		};
		thiz = this;
	}

	componentWillMount(){
		storage.load({
			key: 'user',
			autoSync: true,
			syncInBackground: true
		}).then(ret => {
			loginCheckQuery.loginCheckQuery(ret.phone,ret.password,this,function(owner,response){
				console.log(response);
				if(owner)
				{
					if(response.success !== true ){
						console.log('账户验证失败，跳转到登录界面，需要用户手动填写账号和密码进行登录');
					}
					else{
						global.g_user = response.message;
						// owner.setState({account:g_user.phone});
						owner.props.navigator.push({name:'ParentMain',params:{user:g_user}});
						console.log('账户验证成功，直接切换到主界面！用户手机号为：'+g_user.phone);
						
					}
				}
			})
		}).catch(err => {
			this.props.navigator.push({name:'login'});
			console.log('无法从本地读取到用户账号信息，可能第一次使用，也可能是进行了清除缓存操作。切换到用户登录界面');
		})
	}

	render(){
		// var loadPushNoti = null;
		// if(this.state.account != '')
		// {
		// 	loadPushNoti = <PushNotification account={this.state.account} />;
		// }
		return(
			<View style={styles.container}>
				<Text style={styles.text}>正在加载中...</Text>
			</View>); //此处可以添加过场图片
	}
}

const styles = StyleSheet.create({
	container:{
		backgroundColor:'#fff',
		alignItems:'center',
		justifyContent:'center',
		flex:1
	},
	text:{
		fontSize:20,
		color:'#00F',
		textAlign:'center',
	}
})

module.exports = HomePage;

